import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {PageInfo, Student, TongJiGender} from "../student";
import {Observable} from "rxjs";

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
  providedIn: 'root'
})
export class StudentService {
  private uri="api/student/"

  constructor(private http: HttpClient) { }

  save(student:Student){
    this.http.post<Student>(`${this.uri}save`,student,httpOptions).pipe().subscribe(s =>student.id=s.id)
  }

/*分页的*/
  list(pageNum:number,pageSize:number):Observable<PageInfo>{
      var pagination={
      pageNum:pageNum,
      pageSize:pageSize
    }
    return this.http.post<PageInfo>(`${this.uri}list`,pagination,httpOptions).pipe()
  }


  gender():Observable<TongJiGender[]>{
    return this.http.get<TongJiGender[]>(`${this.uri}gender`).pipe()
  }

}
